/*MyPhotoIndex Free Photo Organizer <www.myphotoindex.com>
  Copyright (C) <2006-2009>  <Asaf Yarkoni asaf@yarkoni.net>

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Collections.ObjectModel;
using System.Collections;

namespace MyPhotoIndex.Controls
{
    public partial class MyPhotoIndexPanel : Panel
    {
        private Padding m_frame;
        private Color m_firstColor = Skiner.Default.BackColorGradiantColor1;
        private Color m_secondColor = Skiner.Default.BackColorGradiantColor2;
        private LinearGradientBrush m_topGradiantBrush;

        public MyPhotoIndexPanel()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            m_toolStrip1.Parent = this;
            m_toolStrip1.AutoSize = false;
            m_toolStrip1.Dock = DockStyle.None;
         //   m_toolStrip1.BackColor = Color.Transparent;

            m_frame = new Padding(0, 25, 0, 15);
            UpdateToolbarPosition();

            Rectangle topDrawRect = new Rectangle(m_frame.Left, 0, this.Width - m_frame.Right - m_frame.Left, m_frame.Top);
            m_topGradiantBrush = new LinearGradientBrush(topDrawRect, m_firstColor, m_secondColor, LinearGradientMode.Vertical);
        }

        [Description("Frame attributes")]
        [Category("CView")]
        public Padding Frame
        {
            get { return m_frame; }
            set { m_frame = value; }
        }

        [Description("Frame attributes")]
        [Category("CView")]
        public Color FirstColor
        {
            get { return m_firstColor; }
            set { m_firstColor = value; }
        }

        [Description("Frame attributes")]
        [Category("CView")]
        public Color SecondColor
        {
            get { return m_secondColor; }
            set { m_secondColor = value; }
        }

        [Description("ToolStrip")]
        [Category("CView")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public MyPhtoIndexToolStrip ToolStrip
        {
            get
            {
                return m_toolStrip1;
            }
        }

        protected override void OnClientSizeChanged(EventArgs e)
        {
            UpdateToolbarPosition();

            if (this.Controls.Count <= 1)
            {
                return;
            }

            if (this.Controls.Count <= 2)
            {
                Control control = this.Controls[1];
                control.Dock = DockStyle.None;
                control.Size = new Size(this.Width - m_frame.Right - m_frame.Left, this.Height - m_frame.Bottom - m_frame.Top);

                control.Left = m_frame.Left;
                control.Top = m_frame.Top;
            }

            base.OnClientSizeChanged(e);
        }

        protected override void OnSizeChanged(EventArgs e)
        {
         //   UpdateToolbarPosition();

            base.OnSizeChanged(e);
        }

        private void UpdateToolbarPosition()
        {
            m_toolStrip1.AutoSize = false;
            m_toolStrip1.Top = 0;
            m_toolStrip1.Left = 0;
            m_toolStrip1.Height = m_frame.Top + 1;
            m_toolStrip1.Width = this.Width;

            if (m_toolStrip1.Renderer.GetType() != typeof(MyRenderer))
            {
                m_toolStrip1.Renderer = new MyRenderer();
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            //Color firstColor = m_firstColor;
            //Color secondColor = m_secondColor;

            //if (m_frame.Top > 0)
            //{
            //    Rectangle topDrawRect = new Rectangle(m_frame.Left, 0, this.Width - m_frame.Right - m_frame.Left, m_frame.Top);
            //    e.Graphics.FillRectangle(m_topGradiantBrush, topDrawRect);
            //}

            //if (0 < m_frame.Bottom)
            //{
            //    Rectangle bottomDrawRect = new Rectangle(m_frame.Left, this.Bottom - m_frame.Bottom, this.Width - m_frame.Right - m_frame.Left, m_frame.Bottom);
            //    using (LinearGradientBrush oBrush1 = new LinearGradientBrush(
            //                new Point(bottomDrawRect.Width / 2, bottomDrawRect.Top),
            //                new Point(bottomDrawRect.Width / 2, bottomDrawRect.Bottom),
            //                firstColor, secondColor))
            //    {
            //        e.Graphics.FillRectangle(oBrush1, bottomDrawRect);
            //    }
            //}

            if (m_toolStrip1.Width != this.Width)
            {
                m_toolStrip1.Width = this.Width;
            }
        }

        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            Color firstColor =  Color.FromArgb(227, 239, 255);
            pevent.Graphics.Clear(firstColor);
        }
    }
}
